package com.we823.cms.controller.manage.cms;

import javax.servlet.http.HttpServletRequest;

import com.github.pagehelper.PageInfo;
import com.we823.cms.common.web.pageable.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.we823.cms.common.WebConstants;
import com.we823.cms.controller.manage.AbstractManageController;
import com.we823.cms.model.cms.Article;
import com.we823.cms.repository.service.cms.ArticleService;

@Controller
@RequestMapping(WebConstants.MANAGE_URL+"/article")
public class ArticleManageController extends AbstractManageController<Article, Integer> {

	private String baseUrl = WebConstants.WEB_MANAGE_TEMPLATE_BaseUrl + "article/";
	
	private ArticleService articleService;
	
	@Autowired
	public ArticleManageController(ArticleService articleService) {
		super(articleService);
		super.baseUrl = baseUrl;
		this.articleService = articleService;
		super.entityName="article";
	}

	@Override
	public PageInfo<Article> getData(PageRequest pageRequest,
			HttpServletRequest request, Model model, boolean pageable) {
		PageInfo<Article> articlePage;
		if(pageable){
			articlePage = articleService.findAll(pageRequest);
		}else{
			articlePage = new PageInfo<>(articleService.findAll());
		}
		return articlePage;
	}

	@Override
	public void setIndetity() {
		setResourceIdentity("cms:article");
	}

}
